package se.teamstat.client.dto;

import java.util.Iterator;
import java.util.Set;

import se.teamstat.client.gui.widgets.helper.Result;

public class PlayerDTO extends EntityDTO {

	private static final long serialVersionUID = -2725114249238858351L;

	public enum Player { ID("id"), FIRST_NAME("firstName"), LAST_NAME("lastName"), EMAIL("email");
		private final String key; 
    	
    	Player(String key) {
    		this.key = key;
    	}
    	public String getKey()   { 
    		return key;
    	}
	}
	
	private Long id;
	private String firstName;
	private String lastName;
	private String email;
	
	public void setMember(Result<String, String> map) {
		Set<String> keys = map.getKeys();
		Iterator<String> keyIterator = keys.iterator();
		while(keyIterator.hasNext()) {
			String key = keyIterator.next();
			if (Player.FIRST_NAME.getKey().equals(key)) {
				firstName = map.getValue(key);
			} else if (Player.LAST_NAME.getKey().equals(key)) {
				lastName = map.getValue(key);
			} else if (Player.EMAIL.getKey().equals(key)) {
				email = map.getValue(key);
			} else if (Player.ID.getKey().equals(key)) {
				id = Long.valueOf(map.getValue(key));
			}
		}
	}

	public String getFirstName() {
		return firstName;
	}
	
	public void setId(Long id) {
		this.id = id;
	}

	public Long getId() {
		return id;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
	
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append(id);
		sb.append(",");
		sb.append(firstName);
		sb.append(",");
		sb.append(lastName);
		sb.append(",");
		sb.append(email);
		return sb.toString();
	}
}
